package o;

import android.app.Activity;
import android.content.Context;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.productpurchase.api.ProductDetailBean;
import com.huawei.appgallery.productpurchase.impl.cache.DpsProductDetail;
import com.huawei.hms.support.api.iap.GetBuyIntentResult;
import o.crh.b;

public class cro {
    private static final Object ˎ = new Object();
    private static cro ॱ;
    private int ʻ = 0;
    private String ʼ;
    private String ʽ;
    private ProductDetailBean ˊ;
    private Context ˋ = ˎ();
    private crj ˏ;
    private DpsProductDetail ॱॱ;

    public static cro ˏ() {
        cro o_cro;
        synchronized (ˎ) {
            if (ॱ == null) {
                ॱ = new cro();
            }
            o_cro = ॱ;
        }
        return o_cro;
    }

    public void ˏ(@NonNull Activity activity, @NonNull ProductDetailBean productDetailBean, crj o_crj) {
        crf.ˎ.ˋ("ProductPurchaseManager", "The process of product purchase starts.");
        this.ˋ = activity;
        this.ˏ = o_crj;
        this.ˊ = productDetailBean;
        ˎ(1);
        csq.ˎ(activity, this.ˊ.ﾞ());
        if (doo.ˊ(this.ˋ)) {
            cvt o_csf = new csf();
            o_csf.ʼ(productDetailBean.ͺˏ());
            o_csf.ˊ(productDetailBean.ॱ());
            o_csf.ˏ(productDetailBean.ꜟ());
            cfw.ˎ(o_csf, new cru(productDetailBean));
            return;
        }
        cso.ˊ(this.ˋ, b.ˋ);
        ˏ(7);
    }

    public void ˊ(DpsProductDetail dpsProductDetail) {
        crf.ˎ.ˋ("ProductPurchaseManager", "The process of pay starts.");
        this.ॱॱ = dpsProductDetail;
        if (this.ˊ == null) {
            ˏ(2);
        } else if (dpsProductDetail.ˋ() == 0) {
            long ॱ;
            long parseLong = Long.parseLong(csq.ˎ(dpsProductDetail.ॱ()));
            if (this.ˊ.ꜞ() <= 0) {
                ॱ = csr.ॱ();
            } else {
                ॱ = (long) this.ˊ.ꜞ();
                csr.ˏ((long) this.ˊ.ꜞ());
            }
            if (System.currentTimeMillis() - parseLong < ॱ * 1000) {
                crf.ˎ.ˋ("ProductPurchaseManager", "Repeat Purchase.");
                cso.ˎ(ˎ());
                return;
            }
            crq.ˎ(ˎ(), 1);
        } else if (dpsProductDetail.ˋ() == 1) {
            crq.ˎ(ˎ(), 1);
        } else {
            ˏ(2);
        }
    }

    public void ˋ() {
        if (this.ॱॱ != null) {
            csi.ˋ(13);
            crq.ˊ(ˎ(), this.ॱॱ);
            return;
        }
        ˏ(2);
    }

    public void ˎ(GetBuyIntentResult getBuyIntentResult) {
        crf.ˎ.ˎ("ProductPurchaseManager", "Verify order creator information.");
        if (getBuyIntentResult == null || getBuyIntentResult.getReturnCode() != 0 || this.ॱॱ == null) {
            ˏ(1);
            return;
        }
        cvt o_csc = new csc();
        o_csc.ˊ(getBuyIntentResult.getPaymentData());
        o_csc.ˎ(getBuyIntentResult.getPaymentSignature());
        o_csc.ʼ(this.ॱॱ.ˎ());
        o_csc.ॱ(this.ॱॱ.ʼ());
        cfw.ˎ(o_csc, new crt(ˎ(), getBuyIntentResult));
    }

    public void ॱ(String str, String str2) {
        crf.ˎ.ˎ("ProductPurchaseManager", "Verify order payment information.");
        this.ʽ = str;
        cvt o_csh = new csh();
        o_csh.ˋ(str);
        o_csh.ˎ(str2);
        cfw.ˎ(o_csh, new crv(str));
    }

    public void ˎ(String str, String str2) {
        this.ʼ = str;
        if (this.ʻ == 2) {
            this.ॱॱ = new DpsProductDetail();
            this.ॱॱ.ˋ(0);
        }
        if (this.ॱॱ == null) {
            ˏ(2);
        } else if (this.ॱॱ.ˋ() == 0) {
            String ˎ = cso.ˎ(str2, "purchaseToken");
            if (cgy.ˎ(ˎ)) {
                crf.ˎ.ˏ("ProductPurchaseManager", "Purchase token is null.");
                ˏ(1);
                return;
            }
            crq.ˏ(ˎ(), ˎ);
        } else {
            ˊ();
        }
    }

    public void ˋ(DpsProductDetail dpsProductDetail) {
        crf.ˎ.ˋ("ProductPurchaseManager", "The process of free collection starts.");
        this.ॱॱ = dpsProductDetail;
        if (dpsProductDetail == null) {
            ˏ(2);
        } else if (UserSession.getInstance().isLoginSuccessful()) {
            csi.ˋ(4);
            cvt o_cry = new cry();
            o_cry.ʼ(dpsProductDetail.ˎ());
            o_cry.ˎ(dpsProductDetail.ॱ());
            o_cry.ˊ(dpsProductDetail.ᐝ());
            cfw.ˎ(o_cry, new crp());
        } else {
            csq.ˊ(false);
            csi.ˋ(11);
            eoj.ˋ().ˎ("ProductPurchaseManager", new csb());
            eod.ॱ(ˏ().ˎ());
        }
    }

    public void ˎ(String str) {
        this.ʼ = str;
        ˊ();
    }

    public void ॱ(ProductDetailBean productDetailBean, DpsProductDetail dpsProductDetail) {
        crf.ˎ.ˋ("ProductPurchaseManager", "The process of jumping  to the third app starts.");
        ((cfb) cdb.ॱ(cfb.class)).ˊ(productDetailBean.ͺˏ(), new crw(ˎ(), productDetailBean, dpsProductDetail));
    }

    public void ˊ() {
        if (this.ʻ == 3) {
            this.ʻ = 1;
            ˋ();
            return;
        }
        if (this.ʻ == 1) {
            if (this.ॱॱ != null) {
                csq.ˊ(this.ॱॱ.ॱ(), String.valueOf(System.currentTimeMillis()));
            }
            if (this.ˊ != null && this.ˊ.ꜞ() > 0) {
                csr.ˏ((long) this.ˊ.ꜞ());
            }
            cso.ॱ(ˎ(), this.ʼ);
        }
        crf.ˎ.ˋ("ProductPurchaseManager", "Process Success");
        if (this.ˏ != null) {
            ProductDetailBean productDetailBean = new ProductDetailBean();
            productDetailBean.ᶥ(cso.ˎ(this.ʽ, "developerPayload"));
            productDetailBean.ॱͺ(cso.ˎ(this.ʽ, "orderId"));
            productDetailBean.ꜞ(cso.ˎ(this.ʽ, "payOrderId"));
            this.ˏ.ˎ(0, productDetailBean);
        }
        ʽ();
    }

    public void ˏ(int i) {
        crf.ˎ.ˋ("ProductPurchaseManager", "Process Failure. reason = " + i);
        if (this.ʻ == 1 && i == 1) {
            cso.ˊ(ˎ(), b.ॱᐝ);
        }
        if (this.ˏ != null) {
            ProductDetailBean productDetailBean = new ProductDetailBean();
            productDetailBean.ᶥ(cso.ˎ(this.ʽ, "developerPayload"));
            productDetailBean.ॱͺ(cso.ˎ(this.ʽ, "orderId"));
            productDetailBean.ꜞ(cso.ˎ(this.ʽ, "payOrderId"));
            this.ˏ.ˎ(i, productDetailBean);
        }
        ʽ();
    }

    public void ॱ() {
        if (this.ॱॱ == null) {
            ˏ(2);
        } else if (this.ॱॱ.ˋ() == 0) {
            ˏ().ˎ(3);
            crq.ˊ(null);
        } else if (this.ॱॱ.ˋ() == 1) {
            ˏ(5);
        }
    }

    public Context ˎ() {
        if (this.ˋ == null) {
            return ContentManager.getInstant().getContext();
        }
        return this.ˋ;
    }

    public void ˎ(int i) {
        this.ʻ = i;
    }

    public int ॱॱ() {
        return this.ʻ;
    }

    public ProductDetailBean ᐝ() {
        if (this.ˊ == null) {
            this.ˊ = new ProductDetailBean();
        }
        return this.ˊ;
    }

    public DpsProductDetail ʻ() {
        if (this.ॱॱ == null) {
            this.ॱॱ = new DpsProductDetail();
        }
        return this.ॱॱ;
    }

    private void ʽ() {
        this.ˊ = null;
        this.ॱॱ = null;
        this.ʼ = null;
        this.ˏ = null;
        this.ˋ = null;
        this.ʻ = 0;
        csq.ॱ();
    }
}
